$.cdbRecord = function(lHTTP){
    var sortTime = 0;
    var isLoad = 0;
    var myScroll,
        upIcon = $("#up-icon"),
        downIcon = $("#down-icon");
    var scrollHeight = 0;

    $('.cdbRecord .cdbRecord-user-money').text('余额：'+userMoney.toFixed(1)+'元');
    $('.cdbRecord .cdbRecord-premoney').text('押金：'+preMoney.toFixed(1)+'元');

    $.updateUserCdbInfo = function(){
        lHTTP.jsonp("/UserGet?static=1")
            .success(function(json,status){
                //储存用户金额
                userMoney = parseFloat(json.user.money);
                //储存用户赠送金额
                presentMoney = parseFloat(json.user.presentMoney);

                preMoney = parseFloat(json.user.preMoney);

                userTrueMoney = userMoney-presentMoney;

                $('.cdbRecord .cdbRecord-user-money').text('余额：'+userMoney.toFixed(1)+'元');
                $('.cdbRecord .cdbRecord-premoney').text('押金：'+preMoney.toFixed(1)+'元');
            });
    }

    //$.updateUserCdbInfo();

    $.getFreeTime = function(dateTime,longTime){
        var addate = new Date().getTime();

        if((longTime-addate) < 0){
            return "0小时";
        }
        else if((longTime-addate)/1000/60/60/24 >= 1){
            return ((longTime-addate)/1000/60/60/24).toFixed(0)+"天";
        }
        else{
            return ((longTime-addate)/1000/60/60).toFixed(0)+"小时";
        }
    }

    //$.getAddTime = function(dateTime){
    //    var myDate = new Date(Date.parse(dateTime.replace(/-/g, "/")));
    //    alert(myDate)
    //    return myDate.getDay()+'/'+myDate.getMonth()+'/'+myDate.getYear()+' '+myDate.getHours()+':'+myDate.getMinutes();
    //}

    $.getRecordDate = function(isSlideDown){

        if(isSlideDown == 1){
            sortTime = 0;
            $('.cdbRecord .record-history').children().remove();
        }
        if(sortTime != -1){
            //$.getJSON(requestHost+"checkHistoryGet?callback=?&access_token="+access_token+"&type=1&sortTime="+sortTime,function(json){
                lHTTP.jsonp("/checkHistoryGet?type=1&sortTime="+sortTime)
                    .success(function(json,status){
                sortTime = json.sortTime;
                //alert(sortTime)
                //$('#scroller').css('height', '');
                //alert($('#scroller').height());
                if(json.data.length > 0 || json.sortTime == -1) {


                    for (var i = 0; i < json.data.length; i++) {
                        $('.cdbRecord .record-history').append(
                            '<li class="record-data">' +
                            '<div class="record-message">' +
                            '<div class="message">' +
                            '<span class="left-font">充电宝ID号</span>  <span class="right-font">' + json.data[i].cdbSimple + '</span>' +
                            '<br/>' +
                            '<span class="left-font">剩余免费</span> <span class="right-font">' + $.getFreeTime(json.data[i].addTime, json.data[i].expires) + '</span>' +
                            '</div>' +
                            '<img class="type-icon" src="images/borrow-record-icon.png">' +
                            '</div>' +
                            '<div class="shop-message">' +
                            '<img class="shop-icon" src="' + json.data[i].shopModel.logo + '">' +
                            '<span class="time">' + json.data[i].addTime + '</span>' +
                            '<span class="over-time-money">产生费用&nbsp;￥' + parseFloat(json.data[i].overtimeMoney) + '</span>' +
                            '</div>' +
                            '</li>'
                        )
                    }
                    //alert($('#scroller').height());







                }
                else{
                    $('.cdbRecord .record-history').append('<p style="text-align: center">没有更多了！</p>')
                }

                if ($('#scroller').height() < $('#wrapper').height()) {
                    if(scrollHeight == 0){
                        scrollHeight = $('#wrapper').height()*1.05;
                    }
                    $('#scroller').css('min-height', scrollHeight+'px');
                    //alert($('#scroller').height());
                }
                if(isLoad == 0) {
                    isLoad=1;
                    loaded();
                }
                else{
                    myScroll.destroy();
                    loaded();
                }
            })
        }

    }

    $.getRecordDate(1);

    //<script src="components/iscroll/iscroll.js" />
    function loaded () {


         myScroll = new IScroll('#wrapper', { probeType: 3, mouseWheel: true });

        myScroll.on("scroll",function(){
            var y = this.y,
                maxY = this.maxScrollY - y,
                downHasClass = downIcon.hasClass("reverse_icon"),
                upHasClass = upIcon.hasClass("reverse_icon");

            if(y >= 40){
                !downHasClass && downIcon.addClass("reverse_icon");
                return "";
            }else if(y < 40 && y > 0){
                downHasClass && downIcon.removeClass("reverse_icon");
                return "";
            }

            if(maxY >= 40){
                !upHasClass && upIcon.addClass("reverse_icon");
                return "";
            }else if(maxY < 40 && maxY >=0){
                upHasClass && upIcon.removeClass("reverse_icon");
                return "";
            }
        });


            myScroll.on("slideDown",function(){
                    if (this.y > 40) {
                        console.log("slideDown");
                        $.getRecordDate(1);
                        upIcon.removeClass("reverse_icon")
                    }
            });

            myScroll.on("slideUp",function(){
                if(this.maxScrollY - this.y > 40){
                    console.log("slideUp");
                    $.getRecordDate(0);
                    upIcon.removeClass("reverse_icon")
                }
            });


    }


}